package com.qmrssreader.reader;

import com.qmrssreader.reader.R;
import com.qmrssreader.system.CommonConfig;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.BufferType;

public class ArticleDetailActivity extends Activity{

	TextView tvTitle;
	TextView tvLink;
	TextView tvPubDate;
	TextView tvDescription;
	WebView wvDescription;
	Button btnBack;
	Button btnReadMore;
	@Override
	protected void onCreate(Bundle savedInstanceState)  {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fadein, R.anim.fadeout);
		setContentView(R.layout.feed_detail);
		wvDescription=(WebView)findViewById(R.id.feed_description);
		
		tvTitle = (TextView) findViewById(R.id.feed_detail_title);
		tvLink = (TextView) findViewById(R.id.feed_detail_link);
		tvDescription = (TextView) findViewById(R.id.feed_detail_description);
		tvPubDate = (TextView) findViewById(R.id.feed_detail_pubDate);

		btnBack=(Button)findViewById(R.id.btnDetail_Back);
		btnReadMore=(Button)findViewById(R.id.btnDetail_Read_More);
		
		final Bundle extras = getIntent().getExtras();
		tvTitle.setText(extras.getString(CommonConfig.EXTRA_FEED_TITLE, "no data"));
		
		//wvDescription.loadData(extras.getString("feed_description"), "text/html", null);
		wvDescription.loadDataWithBaseURL(null,
				extras.getString(CommonConfig.EXTRA_FEED_DESCRIPTION), "text/html", "UTF-8",
				"aboutlank");
		/*tvDescription.setText(
				Html.fromHtml(extras.getString("feed_description")),
				BufferType.SPANNABLE);*/
		tvPubDate.setText(extras.getString(CommonConfig.EXTRA_FEED_PUBDATE));
		OnClickListener lstBack=new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		};
		btnBack.setOnClickListener(lstBack);
		btnReadMore.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String link=extras.getString(CommonConfig.EXTRA_FEED_LINK);
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
				startActivity(browserIntent);
			}
		});
	}
	
}
